package vip.xiaonuo.h5.royalty.modular.my.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.h5.royalty.modular.my.param.ModifyBankInfoParam;
import vip.xiaonuo.h5.royalty.modular.my.param.WithDrawParam;
import vip.xiaonuo.h5.royalty.modular.my.service.MyService;
import vip.xiaonuo.h5.royalty.modular.my.vo.MyInfoVo;
import vip.xiaonuo.h5.royalty.modular.my.vo.MyBalanceVo;
import vip.xiaonuo.h5.royalty.modular.my.vo.IncomeRecordPage;
import vip.xiaonuo.h5.royalty.modular.my.vo.WithdrawRecordPage;
import vip.xiaonuo.h5.royalty.modular.my.param.IncomeRecordParam;
import vip.xiaonuo.h5.royalty.modular.my.param.WithdrawRecordParam;

import javax.validation.Valid;

/**
 * 我的控制器
 */
@RestController
@RequestMapping("/h5/my")
public class MyController {

    @Resource
    private MyService myService;

    /**
     * 获取我的信息
     * @return 我的信息
     */
    @GetMapping("/getMyInfo")
    public CommonResult<MyInfoVo> getMyInfo() {
        MyInfoVo result = myService.getMyInfo();
        return CommonResult.data(result);
    }

    /**
     * 获取账户余额
     * @return 账户余额
     */
    @GetMapping("/getBalance")
    public CommonResult<MyBalanceVo> getBalance() {
        MyBalanceVo result = myService.getBalance();
        return CommonResult.data(result);
    }

    /**
     * 修改银行卡信息
     * @return 修改银行卡信息
     */
    @PostMapping("/modifyBankInfo")
    public CommonResult<String> modifyBankInfo(@RequestBody @Valid ModifyBankInfoParam modifyBankInfoParam) {
        myService.modifyBankInfo(modifyBankInfoParam);
        return CommonResult.ok();
    }

    /**
     * 获取入账记录列表
     * @param param 查询参数
     * @return 入账记录分页数据
     */
    @PostMapping("/getIncomeRecords")
    public CommonResult<IncomeRecordPage> getIncomeRecords(@RequestBody IncomeRecordParam param) {
        IncomeRecordPage result = myService.getIncomeRecords(param);
        return CommonResult.data(result);
    }
    /**
     * 提现接口
     * @return 提现结果
     */
    @PostMapping("/withdraw")
    public CommonResult<String> withdraw(@RequestBody @Valid WithDrawParam withDrawParam) {
        myService.withdraw(withDrawParam);
        return CommonResult.ok();
    }

    /**
     * 获取提现记录列表
     * @param param 查询参数
     * @return 提现记录分页数据
     */
    @PostMapping("/getWithdrawRecords")
    public CommonResult<WithdrawRecordPage> getWithdrawRecords(@RequestBody WithdrawRecordParam param) {
        WithdrawRecordPage result = myService.getWithdrawRecords(param);
        return CommonResult.data(result);
    }

}
